from rest_framework.serializers import ModelSerializer

from demo_app.models import Goods, Order, Comment


class GoodsSerializer(ModelSerializer):
    class Meta:
        model = Goods
        fields = '__all__'


class CommentSerializer(ModelSerializer):
    class Meta:
        model = Comment
        fields = '__all__'


# 订单读
class OrderReadSerializer(ModelSerializer):
    comment = CommentSerializer()
    class Meta:
        depth = 1  # 序列化时, 把外键也序列化
        model = Order
        fields = '__all__'


# 订单写
class OrderWriteSerializer(ModelSerializer):
    class Meta:
        model = Order
        fields = '__all__'
